﻿package plugin.newxunbao
{
    import __AS3__.vec.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;
    import morn.core.handlers.*;

    public class ItemEffects extends Object
    {
        private var _queue:Array;
        private var _items:Vector.<Bitmap>;
        private var _container:NewXunbaoUIExt;
        private var _intvalid:uint = 0;

        public function ItemEffects(param1:NewXunbaoUIExt)
        {
            this._queue = new Array();
            this._items = new Vector.<Bitmap>;
            this._container = param1;
            return;
        }// end function

        public function add(param1:Object) : void
        {
            var _loc_2:Object = null;
            if (param1 is Array)
            {
                for each (_loc_2 in param1)
                {
                    
                    this._queue.push(_loc_2);
                }
            }
            else
            {
                this._queue.push(_loc_2);
            }
            this.startMove();
            return;
        }// end function

        public function startMove() : void
        {
            if (this._intvalid == 0)
            {
                this._intvalid = setInterval(this.next, 150);
            }
            return;
        }// end function

        private function next() : void
        {
            var _loc_1:Object = null;
            if (this._queue.length > 0)
            {
                _loc_1 = this._queue.shift();
                App.loader.loadBMD(Config.getUrl("assets/images/icon/tools/" + _loc_1.icon + ".png"), new Handler(this.loadedHandler, [_loc_1]));
                if (this._queue.length == 0)
                {
                    this.clearRender();
                }
            }
            return;
        }// end function

        private function loadedHandler(param1:Object, param2:BitmapData) : void
        {
            var _loc_3:Point = null;
            var _loc_4:Bitmap = null;
            if (param2)
            {
                _loc_3 = new Point(this._container.openCkBtn.x, this._container.openCkBtn.y);
                if (_loc_3)
                {
                    _loc_4 = new Bitmap(param2);
                    _loc_4.scaleX = 0.8;
                    _loc_4.scaleY = 0.8;
                    this._items.push(_loc_4);
                    this._container.addChild(_loc_4);
                    if (param1.hasOwnProperty("x"))
                    {
                        _loc_4.x = param1.x;
                        _loc_4.y = param1.y;
                    }
                    else if (param1.middle)
                    {
                        _loc_4.x = this._container.width / 2 - 30;
                        _loc_4.y = this._container.height / 2 - 30;
                    }
                    else
                    {
                        _loc_4.x = this._container.t13.x + 30;
                        _loc_4.y = this._container.t13.y + 30;
                    }
                    TweenLite.to(_loc_4, 3, {x:_loc_3.x + 50, y:_loc_3.y, onComplete:this.tweenEnd, onCompleteParams:[_loc_4], ease:Expo.easeOut});
                }
            }
            return;
        }// end function

        private function tweenEnd(param1:Bitmap) : void
        {
            var _loc_2:* = this._items.indexOf(param1);
            if (_loc_2 > -1)
            {
                this._items.splice(_loc_2, 1);
            }
            if (param1.parent)
            {
                param1.parent.removeChild(param1);
            }
            return;
        }// end function

        private function clearRender() : void
        {
            if (this._intvalid > 0)
            {
                clearInterval(this._intvalid);
                this._intvalid = 0;
            }
            return;
        }// end function

        public function clear() : void
        {
            var _loc_1:Bitmap = null;
            this._queue.length = 0;
            for each (_loc_1 in this._items)
            {
                
                if (_loc_1.parent)
                {
                    _loc_1.parent.removeChild(_loc_1);
                }
            }
            this._items.length = 0;
            this.clearRender();
            return;
        }// end function

    }
}
